package com.zxk.api.service.impl;

import com.zxk.api.dao.FundDao;
import com.zxk.api.service.FundService;
import com.zxk.core.common.model.Fund;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author zxk
 * @description 基金
 * @date 2020/8/28
 */
@Service
public class FundServiceImpl implements FundService {
    @Autowired
    private FundDao fundDao;
    @Autowired
    private FundService fundService;


    @Override
    @Transactional
    public void save(Fund fund) {
        //保存之前查看是否有重复数据
        List<Fund> funds = this.fundService.find(fund);
        if(null != funds && funds.size() > 0){
            return;
        }
        fund.setCreateTime(new Date());
        fund.setIsDelete(0);
        fundDao.save(fund);

    }

    @Override
    public List<Fund> find(Fund fund) {
        Example<Fund> example = Example.of(fund);
        List<Fund> funds = fundDao.findAll(example);
        return funds;
    }

    @Override
    public List<Fund> findNewsByTime(Date date) {
//        https://blog.csdn.net/long476964/article/details/79677526
//        News news = new News();
//        news.setCreateTime(date);
//        List<News> list = this.fundAnalysiseDao.selectNewsByTime(date);
        return null;
    }

    @Override
    @Transactional
    public List<Fund> findAll() {
        List<Fund> list = this.fundDao.findAll();
        return list;
    }

    @Override
    public List<Fund> selectOrderFundByCreateTime() {
        List<Fund> funds = this.fundDao.findByCreateTime();
        return funds;
    }
}
